package com.rw.bootcar.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.rw.bootcar.pojo.User;
import com.rw.bootcar.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;


    @RequestMapping("reg")
    public String registerUser(User user) throws JsonProcessingException {
        //校验参数
        System.out.println(user);
        boolean flag = userService.register(user);
        if (flag){
            return "user";
        }else {
            return "error";
        }

    }

    @GetMapping("active/{id}")
    public String activeUser(@PathVariable Integer id){
        userService.active(id);
        return "index";
    }

}
